package cn.mesmile.flow.modules.processtask.controller;

import cn.mesmile.flow.config.test.Student;
import cn.mesmile.flow.modules.processtask.model.dto.CompleteTaskDTO;
import cn.mesmile.flow.modules.processtask.model.vo.CompleteTaskVO;
import cn.mesmile.flow.modules.processtask.model.vo.QueryTaskVO;
import cn.mesmile.flow.modules.processtask.service.ProcessTaskService;
import lombok.AllArgsConstructor;
import org.flowable.bpmn.model.BpmnModel;
import org.flowable.bpmn.model.FlowNode;
import org.flowable.bpmn.model.SequenceFlow;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Scanner;

/**
 * @author zb
 * @date 2020/12/7 15:54
 * @Description
 */
@AllArgsConstructor
@RequestMapping("/api/v1/task")
@RestController
public class ProcessTaskController {

    private final ProcessTaskService processTaskService;

    @GetMapping("/get")
    public List<QueryTaskVO> get() {
        List<QueryTaskVO> queryTaskVOList = processTaskService.get();
        return queryTaskVOList;
    }

    @PostMapping("/complete")
    public CompleteTaskVO complete(@RequestBody CompleteTaskDTO completeTaskDTO) {
        CompleteTaskVO completeTaskVO = new CompleteTaskVO();

        processTaskService.completeTask(completeTaskDTO);

        return completeTaskVO;
    }

    @GetMapping("rollabck")
    public void test(){
        // 获取当前节点的activityId,即xml中每个标签的ID
//        String currentActivityId = execution.getCurrentActivityId();

//        List<Task> list1 = taskService.createTaskQuery().processInstanceId(processInstance.getProcessInstanceId()).list();
//                taskService.addComment(currentTask.getId(), execution.getProcessInstanceId(), body.get("msg").toString());

//        BpmnModel bpmnModel = repositoryService.getBpmnModel(execution.getProcessDefinitionId());
//        FlowNode flowNode = (FlowNode)bpmnModel.getFlowElement(currentActivityId);
//        SequenceFlow sequenceFlow = flowNode.getIncomingFlows().get(0);
        // 获取上一个节点的activityId
//        String sourceRef = sequenceFlow.getSourceRef();

        // 流程回退到上一个节点，审批人继续审批
//        runtimeService.createChangeActivityStateBuilder().processInstanceId(processInstance.getProcessInstanceId())
//                .moveActivityIdTo(currentActivityId,sourceRef).changeState();
    }

}
